package com.hitechbangla.fctu.base.radar;

import com.hitechbangla.fctu.base.LocationInteger;
import com.hitechbangla.fctu.base.aircraft.Aircraft;
import fctu.simulator.HTB_MAIN;
import java.awt.Color;
import java.awt.Graphics;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author deb kanti
 */
// this is a small version of the aircraft class to print the path in radar

public class AircraftForPath  implements Serializable
{
    private String callSign;
    List<LocationInteger> listPath;    
    private int pathSize;
    Aircraft aircraft = new Aircraft();
    
    public AircraftForPath()
    {
	listPath = new ArrayList<>();	
    }
    
    public void addLocation(int positionX, int positionY, int pathSize)
    {
	if(listPath.size()==4)
	{
	    listPath.remove(0);	    
	}
	listPath.add(new LocationInteger(positionX,positionY));
	////System.out.println("from aircraftforpath:" + callSign + " , location size " + listPath.size());
    }
    
    public void draw(Graphics g)
    {
	int rectangleSize = 8;
	
	g.setColor(Color.BLACK);
        //if(aircraft.isIffSignalCheck())
        
        Aircraft aircraft =  getAircraftOnCallSign(callSign);
        
        
	
	for(int i = listPath.size()-1; i>=0;i--)
	{	  
	    //System.out.println("count no:" + (i+1));
	    
	    int positionX = (int)((listPath.get(i).getX())*HTB_MAIN.one_px_equivalent_naut-rectangleSize/2);
	    int positionY = (int)((listPath.get(i).getY())*HTB_MAIN.one_px_equivalent_naut-rectangleSize/2);
	    	    
	   // //System.out.println("from aircraftforpath, positionx: " + positionX + ", positiony: " + positionY);
	   // //System.out.println("from aircraftforpath, x: " + listPath.get(i).getX() + ", positiony: " + listPath.get(i).getY());	    
	 
            if(i==listPath.size()-1)
            {
                if(aircraft.isIffSignalCheck())
                {
                    g.drawRect(positionX, positionY, rectangleSize,rectangleSize);
                }   
                else
                {
                    g.fillRect(positionX, positionY, rectangleSize,rectangleSize);
                }
            }
            else
            {
                g.fillRect(positionX, positionY, rectangleSize,rectangleSize);
            }
          
           
            
	    rectangleSize -=2;
	    
	    
	    
	    ////System.out.println("from aircraftforpath: x " + positionX + ",y " + positionY);
	}
    }
    
     private Aircraft getAircraftOnCallSign(String callSign)
    {
        List<Aircraft> aircraftList = HTB_MAIN.gameScene.airCraftList;
        for(Aircraft aircraft: aircraftList)
        {
            if(aircraft.getAircraftState().getCallSign().equals(callSign))
            {
                return aircraft;
            }
        }
        return null;
    }

    /**
     * @return the callSign
     */
    public String getCallSign() {
	return callSign;
    }

    /**
     * @param callSign the callSign to set
     */
    public void setCallSign(String callSign) {
	this.callSign = callSign;
    }
    
    public static void main(String a[])
    {
    
        
    }
    
}
